package org.study.date;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * @author Administrator
 */
public class DateTest01 {
    public static void main(String[] args) {
        // test01();
        // test02();
        test03();
    }

    public static void test01() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate startDate = LocalDate.parse("2019-01-02", formatter);
        LocalDate endDate = LocalDate.parse("2020-01-01", formatter);
        // 日期区间
        long days = ChronoUnit.DAYS.between(startDate, endDate);
        // 月
        long month = ChronoUnit.MONTHS.between(startDate, endDate);
        // 年
        long year = ChronoUnit.YEARS.between(startDate, endDate);
        System.out.println(year + ", " + month + ", " + days);
    }

    public static void test02() {
        // 当前日期的前一天：昨天
        LocalDate start = LocalDate.of(2020, 11, 16);
        LocalDate end = LocalDate.of(2020, 11, 20);
        while (start.isBefore(end)) {
            System.out.println(start);
            start = start.plusDays(1);
        }
        System.out.println(end.isBefore(end));
        System.out.println(end.equals(end));
        System.out.println(end.isAfter(end));
    }

    public static void test03() {
        LocalDate today = LocalDate.now();
        LocalDate yesterday = today.minusDays(1);
        LocalDate tomorrow = today.plusDays(1);
        System.out.println("yesterday.isBefore(today)：" + yesterday.isBefore(today));
        System.out.println("yesterday.isAfter(today)：" + yesterday.isAfter(today));

        System.out.println("yesterday.compareTo(yesterday)：" + yesterday.compareTo(yesterday));
        System.out.println("yesterday.compareTo(today)：" + yesterday.compareTo(today));
        System.out.println("yesterday.compareTo(today)<=0：" + (yesterday.compareTo(today) <= 0));


        System.out.println("yesterday.isBefore(today)：" + (yesterday.compareTo(today) <= 0));
        System.out.println("today.isAfter(tomorrow)：" + today.isAfter(tomorrow));
    }
}
